require 'Common/define'
require 'Logic/Config'
require 'Common/functions'

UISearching = {}
HelperFunc.SetUIEnv(UISearching)
local this = UISearching

function UISearching.Init(data, closeFunc) 
    local _name, _package = getUIName(PanelNames.UISearching)
    panelMgr:ShowUI(_name, _package, this.onCreate, Config.useLocalUI)
end

function UISearching.onCreate(obj)
    if not this.hasInit then
        this.hasInit = true 
        this.txt_countdown = obj:GetChild("Text_CountDown") 
    end 
    this.initData()
    AudioManager.Play(2027)
end
 
function UISearching.initData()  
    this.count = 3
    this.timer_id = utimer.timeCall(function() 
        this.count = this.count - 1 
        if this.count <= 0 then
            if this.timer_id ~= nil then
                utimer.remove(this.timer_id)
                this.timer_id = nil
            end
            plunderHandler.sendReqPlunderSearch() 
            this.CloseSelf() 
        end
    end, 1000, 3) 
end

function UISearching.CloseSelf() 
    DestoryUI(PanelNames.UISearching)
end

function UISearching.OnDestroy() 
    if this.timer_id ~= nil then
        utimer.remove(this.timer_id)
        this.timer_id = nil
    end 
    this.hasInit = nil
    this.root = nil
end

return UISearching
